function [data]=show_last_stack(exp,aux,splitdata,ch_combined)

if nargin<1
    exp=0;
end
if nargin<2
    aux=0;
end
if nargin<3
    splitdata=1;
end
if nargin<4
    ch_combined=1;
end

tmp_dir='D:\tempData\';
aux_dir='H:\';
% tmp_dir='D:\data\dump\';
% aux_dir='D:\data\dump\';
aux_ch_frame_times = 2;
aux_ch_plot = [3,4];
% splitdata = 1; % split data if piezo layering occurred

if exp==0
    previous=0;
    tmpfiles=dir([tmp_dir '*.bin']);
    tmpfiles=struct2cell(tmpfiles);
    [~,tmp_time_ind]=sort(cell2mat(tmpfiles(5,:)));
    fname=tmpfiles{1,tmp_time_ind(end-previous)};
else
    tmpfiles=dir([tmp_dir '*.bin']);
    tmpfiles=struct2cell(tmpfiles);
    exp=num2str(exp);
    fnameCh1=['S1-T' exp '_ch610.bin'];
    fnameCh2=['S1-T' exp '_ch525.bin'];
    srchCh1=strcmp(fnameCh1,tmpfiles(1,:));
    srchCh2=strcmp(fnameCh2,tmpfiles(1,:));
    if isempty(find(srchCh1))==0 & isempty(find(srchCh2))~=0
        fname=fnameCh1;
    elseif isempty(find(srchCh1))~=0 & isempty(find(srchCh2))==0
        fname=fnameCh2;
    elseif isempty(find(srchCh1))==0 & isempty(find(srchCh2))==0
        disp(['Exp files from both channels recorded'])
        load_ch=input(['Load ch610 (0) ch525 (1) or both (2)? ']);
        if load_ch==0
            fname=fnameCh1;
        elseif load_ch==1
            fname=fnameCh2;
        else
            fname={fnameCh1 fnameCh2};
        end
    else
        disp(['Exp not found'])
    end
end

if exist('fname','var')
    if ~isa(fname,'cell')
        disp(['last stack: ' fname]);
        % % %         if aux
        % % %             stack_date = tmp_time(tmp_time_ind(end-previous));
        % % %             aux_dir_day = datestr(tmpfiles{2,tmp_time_ind(end-previous)},'yyyy-mm-dd');
        % % %             tmpfiles=dir([aux_dir aux_dir_day '\*.lvd']);
        % % %             tmpfiles=struct2cell(tmpfiles);
        % % %             tmp_time2=datenum(tmpfiles(2,:),'dd-mmm-yyyy HH:MM:SS');
        % % %             fname2=tmpfiles{1, abs((tmp_time2-stack_date)) < 0.0001};
        % % %             disp(['rec file:   ' aux_dir_day '\' fname2]);
        % % %         end
        % % %
        % % %         % image_info=imfinfo(['C:\TEMPOUT\' fname]);
        % % %         %
        % % %         % %by default read all frames
        % % %         % number_of_frames=length(image_info);
        % % %         %
        % % %         % %initialize the data array
        % % %         % data=zeros(image_info(1).Height,image_info(1).Width,number_of_frames,'uint16');
        % % %         %
        % % %         % for ind=1:number_of_frames
        % % %         %     data(:,:,ind)=uint16(imread(['C:\TEMPOUT\' fname],ind,'Info',image_info));
        % % %         % end
        % % %
        % % %         if aux
        % % %             data=load_bin([tmp_dir fname]);
        % % %             aux_data=load_lvd(fullfile(aux_dir,aux_dir_day,fname2));
        % % %             frame_times = get_frame_times(aux_data(aux_ch_frame_times,:));
        % % %             view_tiff_stack_plot_aux(data,aux_data(aux_ch_plot,frame_times)');
        % % %         else
        % % %             data=load_bin([tmp_dir fname]);
        % % %             view_tiff_stack(data)
        % % %         end
        data=load_bin([tmp_dir fname]);
        inidata = readini([tmp_dir regexprep(fname,'.bin','.ini')]);
        if splitdata && inidata.piezo.nbrlayers > 1
            dim = size(data);
            try
                data = reshape(data,dim(1),dim(2)*inidata.piezo.nbrlayers,dim(3)/inidata.piezo.nbrlayers);
            end
        end
        view_tiff_stack(data)
    elseif size(fname,2) == 2 && ch_combined
        ind = 1;
        fname{ind}
        data1=load_bin([tmp_dir fname{ind}]);
        inidata = readini([tmp_dir regexprep(fname{ind},'.bin','.ini')]);
        if splitdata && inidata.piezo.nbrlayers > 1
            dim = size(data1);
            data1 = reshape(data1,dim(1),dim(2)*inidata.piezo.nbrlayers,dim(3)/inidata.piezo.nbrlayers);
        end
        
        ind = 2;
        fname{ind}
        data=load_bin([tmp_dir fname{ind}]);
        inidata = readini([tmp_dir regexprep(fname{ind},'.bin','.ini')]);
        if splitdata && inidata.piezo.nbrlayers > 1
            dim = size(data);
            data = reshape(data,dim(1),dim(2)*inidata.piezo.nbrlayers,dim(3)/inidata.piezo.nbrlayers);
        end
        
        view_tiff_stack(data1,'',data);
    else
        for ind=1:size(fname,2)
            fname{ind}
            data=load_bin([tmp_dir fname{ind}]);
            inidata = readini([tmp_dir regexprep(fname{ind},'.bin','.ini')]);
            if splitdata && inidata.piezo.nbrlayers > 1
                dim = size(data);
                data = reshape(data,dim(1),dim(2)*inidata.piezo.nbrlayers,dim(3)/inidata.piezo.nbrlayers);
            end
            view_tiff_stack(data)
        end
    end
end
